﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace AudioDemo.View
{
    /// <summary>
    /// media3.xaml 的交互逻辑
    /// </summary>
    public partial class media3 : Window
    {
        public media3()
        {
            InitializeComponent();
        }

        //播放按钮
        private void button_Click(object sender, RoutedEventArgs e)
        {
            if (button.Content.ToString() == "播放")
            {
                button.Content = "暂停";
                mediaElement.Play();
            }
            else
            {
                button.Content = "播放";
                mediaElement.Pause();
            }
        }
DispatcherTimer timer = null;
private void mediaElement_MediaOpened(object sender, RoutedEventArgs e)
{
    sliderPosition.Maximum = mediaElement.NaturalDuration.TimeSpan.TotalSeconds;
    //媒体文件打开成功
    timer = new DispatcherTimer();
    timer.Interval = TimeSpan.FromSeconds(1);
    timer.Tick += new EventHandler(timer_tick);
    timer.Start();
}
private void timer_tick(object sender, EventArgs e)
{
    sliderPosition.Value = mediaElement.Position.TotalSeconds;
}
        //控制视频的位置
        private void sliderPosition_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            //mediaElement.Stop();
            mediaElement.Position = TimeSpan.FromSeconds(sliderPosition.Value);
            //mediaElement.Play();
        }


    }
}
